<?php
class CurlUtil {
	private $url;
	private $httpheader = array (
		"Content-Type: text/xml;charset=utf-8"
	);
	private $header = 0;
	private $retuurnransfer = 1;
	private $ch = null;
	private $binarytransfer = null;
	private $encoding = null;
	private $post_fields = null;
	private $cookie_file = null;
	private $referer = null ;
	private $userAgent = null ;
	private $fp = null;
	private $https = false;
	private $state ;
	function CurlUtil($url) {
		$this->url=$url;

	}

	public function init() {
		$this->ch = curl_init();
		curl_setopt($this->ch,CURLOPT_TIMEOUT,10);
		curl_setopt($this->ch, CURLOPT_URL, $this->url);
		if($this->fp !=null ) {  
			curl_setopt($this->ch, CURLOPT_FILE , $this->fp );
		}
		curl_setopt($this->ch, CURLOPT_HEADER, $this->header);
		if(!$this->https) {
			curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, $this->retuurnransfer);
		}
		if($this->post_fields == null ) {
			curl_setopt($this->ch, CURLOPT_HTTPHEADER, $this->httpheader);
		}
		if($this->https) {
			curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, FALSE);
			curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 1);
		}
		if($this->referer)
			curl_setopt($this->ch, CURLOPT_REFERER,$this->referer);
		if (null != $this->binarytransfer) {
			curl_setopt($this->ch, CURLOPT_BINARYTRANSFER, $this->binarytransfer);
		}
		if (null != $this->userAgent) {
			curl_setopt($this->ch, CURLOPT_USERAGENT, $this->userAgent) ;
		}
		if (null != $this->encoding) {
			curl_setopt($this->ch, CURLOPT_ENCODING, $this->encoding);
		}
		
		if(null != $this->post_fields) {
			curl_setopt($this->ch, CURLOPT_POST, 1);
			curl_setopt($this->ch, CURLOPT_POSTFIELDS, $this->post_fields);
		}
		if(null != $this->cookie_file ) {
			curl_setopt($this->ch, CURLOPT_COOKIEJAR, $this->cookie_file);
			curl_setopt($this->ch, CURLOPT_COOKIEFILE, $this->cookie_file);
		}
		
		
	}

	public function getBody() {
		$output = curl_exec($this->ch);
		$this->state = curl_getinfo($this->ch,CURLINFO_HTTP_CODE);
		curl_close($this->ch);
		return $output;
	}
	
	
	private function __get($property_name) {
		return $this->$property_name;

	}

	private function __set($property_name, $value) {
		$this->$property_name = $value;
	}
}
?>